/*
 * @Author: Eureka 
 * @Date: 2020-09-11 18:44:24 
 * @Last Modified by: Eureka
 * @Last Modified time: 2020-10-13 11:38:39
 */

class EmptyUtil {
  /// 检查对象或 List 或 Map 是否为空
  static bool isEmpty(Object? object) {
    if (object == null) return true;
    if (object is String && object.isEmpty) {
      return true;
    } else if (object is List && object.isEmpty) {
      return true;
    } else if (object is Map && object.isEmpty) {
      return true;
    }
    return false;
  }

  static List toList(List list) {
    try {
      return list.where((a) => (a.length > 0)).toList();
    } catch (e) {
      return [];
    }
  }

  static int safeInt(Object? object) {
    if (object == null) {
      return 0;
    } else if (object is int) {
      return object;
    } else {
      return 0;
    }
  }

  static String isEmptyString(String string) {
    try {
      if (isEmpty(string)) {
        return "";
      } else {
        return string;
      }
    } catch (e) {
      return "";
    }
  }

  static int stringToInt(dynamic string) {
    try {
      if (isEmpty(string)) {
        return 0;
      } else {
        return int.parse(string);
      }
    } catch (e) {
      return 0;
    }
  }

  static String stringToFiexed(dynamic string, int fiexd) {
    try {
      if (isEmpty(string)) {
        return "";
      } else {
        return string.toStringAsFixed(fiexd);
      }
    } catch (e) {
      return "";
    }
  }

  static String isEmptyStringWithMeterial(String string) {
    if (isEmpty(string)) {
      return "无";
    } else {
      return string;
    }
  }

  static String isEmptyNumToString(dynamic number) {
    try {
      if (isEmpty(number)) {
        return "";
      } else {
        return number.ceil().toString();
      }
    } catch (e) {
      return "";
    }
  }

  static String isEmptyNumString(dynamic numbar) {
    try {
      if (isEmpty(numbar)) {
        return " ";
      } else if (numbar == 0) {
        return " ";
      } else {
        return numbar.toString();
      }
    } catch (e) {
      return "";
    }
  }

  static String doubleToString(dynamic numbar) {
    try {
      if (isEmpty(numbar)) {
        return "";
      } else {
        return numbar.toString();
      }
    } catch (e) {
      return "";
    }
  }

  static String intToString(int numbar) {
    try {
      if (isEmpty(numbar)) {
        return "0";
      } else {
        return numbar.toString();
      }
    } catch (e) {
      return "0";
    }
  }

  static double stringToDuble(String numbar) {
    try {
      if (isEmpty(numbar)) {
        return .0;
      } else {
        return double.parse(numbar);
      }
    } catch (e) {
      return .0;
    }
  }
}
